﻿<UserControl x:Class="Microsoft.Forums.ForumsClient.Views.SubscribeToForumsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:ForumsClient="clr-namespace:Microsoft.Forums.ForumsClient"
    xmlns:Views="clr-namespace:Microsoft.Forums.ForumsClient.Views"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="{DynamicResource DefaultWindowBackground}">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="IsThisForumNew" />
        <BooleanToVisibilityConverter x:Key="IsThisUserModerator" />
        <Views:NegatedBooleanToVisibleConverter x:Key="IsThisForumPublic" />
            
        <DataTemplate x:Key="NewIconTemplate">
            <Image x:Uid="NewIconTemplateImage" Margin="0,6,0,5" Width="16" Height="16" Source="Images\BlueNew.ico" Visibility="{Binding Path=IsNewForum, Converter={StaticResource IsThisForumNew}}" Name="NewIconTemplateImage" ToolTip="New forum since you last used this dialog." />
        </DataTemplate>

        <DataTemplate x:Key="ModeratorIconTemplate">
            <Image x:Uid="ModeratorIconTemplateImage" Margin="0,5,0,5" Height="16" Width="16" Source="Images\Moderator.ico" Name="ModeratorIconImage" Visibility="{Binding Path=IsModerator, Converter={StaticResource IsThisUserModerator}}" ToolTip="You are a moderator in this forum." />
        </DataTemplate>

        <DataTemplate x:Key="PublicForumIconIconTemplate">
            <Image x:Uid="PublicForumIconIconTemplateImage" Margin="0,6,0,5" Height="24" Width="24" Source="Images\BlueUnlocked.ico" Name="PublicForumIconImage" Visibility="{Binding Path=IsPrivate, Converter={StaticResource IsThisForumPublic}}" ToolTip="This is a public forum." />
        </DataTemplate>

        <DataTemplate x:Key="DescriptionExpanderTemplate">
            <Expander  Width="340" IsExpanded="False" Header="{Binding Path=Description}"  >
                <TextBlock x:Uid="ForumDetailsTemplateDescriptionTextBlock" Text="{Binding Path=Description}" TextWrapping="Wrap" />
			</Expander>
        </DataTemplate>

        <DataTemplate x:Key="AvailableForumNameTemplate" >
            <TextBlock Text="{Binding Path=DisplayName}" />
        </DataTemplate>


    </UserControl.Resources>
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static ForumsClient:Commands.AddToPreviewArea}"  CanExecute="AddToPreviewArea_CanExecute" Executed="AddToPreviewArea_Executed" />
        <CommandBinding Command="{x:Static ForumsClient:Commands.RemoveFromPreviewArea}"  CanExecute="RemoveFromPreviewArea_CanExecute" Executed="RemoveFromPreviewArea_Executed" />
    </UserControl.CommandBindings>
    <Grid>
        <!--Image x:Uid="background"  Margin="0,0,-337.333,-171.333" x:Name="background" Style="{DynamicResource BackgroundStyle}" Stretch="Fill"/ -->
        <Grid  x:Uid="Grid_1" Margin="10,10,10,15" >
            <Grid.RowDefinitions>
                <RowDefinition x:Uid="RowDefinition_0" Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_3" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_4" Height="*"/>
                <RowDefinition x:Uid="RowDefinition_5" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_6" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_7" Height="Auto"/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" HorizontalAlignment="Stretch" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Label Grid.Row="0" FontSize="16" FontWeight="Bold" Content="Subscribe to Forums" HorizontalAlignment="Center"  />
            </Grid>
            
            <GroupBox Grid.Row="1" HorizontalAlignment="Stretch" BorderBrush="{DynamicResource DefaultBorder}">
                <GroupBox.Header>
                    <Label Content="Set Your Preferences and Filters" Grid.Row="0" />
                </GroupBox.Header>

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition x:Uid="RowDefinition_1" Height="Auto"/>
                        <RowDefinition x:Uid="RowDefinition_2" Height="Auto"/>
                    </Grid.RowDefinitions>
                    <!-- Filter Grid -->
                    <Grid x:Uid="Grid_2" Grid.Row="0" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition x:Uid="RowDefinition_8" Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Uid="ColumnDefinition_1" Width="0.39*" />
                            <ColumnDefinition x:Uid="ColumnDefinition_2" Width=".175*" />
                            <ColumnDefinition x:Uid="ColumnDefinition_3" Width=".175*" />
                            <ColumnDefinition x:Uid="ColumnDefinition_4" Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <StackPanel x:Uid="StackPanel_14" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                            <Label x:Uid="FilterLabel" Height="25" Margin="5" Name="FilterLabel" Content="Filter Name and Description" ToolTip="Display forums that contain the search text in their name or description." />
                            <TextBox x:Uid="FilterTextBox" Name="FilterTextBox" Height="25" Width="110" Text="{Binding Path=FilterByText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             IsEnabled="{Binding Path=IsDoneLoading}" ToolTip="Display forums that contain the search text in their name or description." />
                        </StackPanel>
                        <StackPanel x:Uid="StackPanel_15" Orientation="Horizontal" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Top">

                            <Label x:Uid="BrandLabel" Height="25" Margin="5" Name="BrandLabel" Content="Brand"  />
                            <ComboBox IsEnabled="{Binding Path=IsDoneLoading}" x:Uid="BrandComboBox" Height="25" Margin="0,5,5,5" Name="BrandComboBox" 
                              ItemsSource="{Binding Path=BrandsCollectionView}"
                              MinWidth="70" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" ToolTip="Display forums available in a particular brand">
                            </ComboBox>
                        </StackPanel>
                        <StackPanel x:Uid="StackPanel_16" Orientation="Horizontal" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                            <Label x:Uid="LocaleLabel" Height="25" Margin="5" Name="LocaleLabel" Content="Locale" />
                            <ComboBox x:Uid="LocaleComboBox" Height="25" Margin="0,5,5,5" SelectedIndex="-1" Name="LocaleComboBox" 
                              IsEnabled="{Binding Path=IsDoneLoading}" 
                              ItemsSource="{Binding Path=LocaleCollectionView}"  
                              MinWidth="70" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" ToolTip="Display forums available in a particular locale"  >
                            </ComboBox>
                        </StackPanel>
                        <StackPanel x:Uid="StackPanel_17" Orientation="Horizontal" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                            <Label x:Uid="ShowLabel" Height="25" Margin="5" Name="ShowLabel" Content="Show"  />
                            <ComboBox x:Uid="ShowComboBox" IsEnabled="False" IsSynchronizedWithCurrentItem="True" Width="40" Margin="0,5,5,5" Height="25" SelectedIndex="0" Name="ShowComboBox">
                                <ComboBoxItem x:Uid="AllComboBoxItem" Content="All"/>
                                <ComboBoxItem x:Uid="NewComboBoxItem" Content="New"/>
                            </ComboBox>
                        </StackPanel>
                    </Grid>

                    <!-- Settings Grid -->
                    <Grid x:Uid="Grid_3" Grid.Row="2" HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition x:Uid="RowDefinition_9" Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Uid="ColumnDefinition_5" Width="0.35*" />
                            <ColumnDefinition x:Uid="ColumnDefinition_6" Width=".32*" />
                            <ColumnDefinition x:Uid="ColumnDefinition_7" Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <StackPanel x:Uid="StackPanel_18" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch"  Orientation="Horizontal" >
                            <Label x:Uid="DaysLabel" Height="25" Margin="5" Name="DaysLabel" Content="Days of Threads in Initial Download" ToolTip="First download will include threads with activity in the past N days. In subsequent synchronizations, you get all posts since you last synchronized." />
                            <ComboBox x:Uid="DaysComboBox" IsEnabled="{Binding Path=IsDoneLoading}" 
                              IsSynchronizedWithCurrentItem="True" MinWidth="50" Margin="5,10,5,10" Height="25"
                              ItemsSource="{Binding Path=SyncFromAgeCollectionView}"
                              Name="DaysComboBox" ToolTip="First download will include threads with activity in the past N days. In subsequent synchronizations, you get all posts since you last synchronized.">

                            </ComboBox>
                        </StackPanel>
                        <StackPanel x:Uid="StackPanel_19" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch"   >
                            <Label x:Uid="Label_1" Margin="0" Width="50"></Label>

                            <Label x:Uid="Label_2" Margin="0" Width="50"></Label>
                        </StackPanel>
                        <StackPanel x:Uid="StackPanel_20" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Stretch"   >

                            <CheckBox x:Uid="CategoryCheckBox" Name="CategoryCheckBox" IsEnabled="False"  Margin="5,16,5,13" VerticalAlignment="Bottom" Content="Group by categories"  />
                        </StackPanel>
                    </Grid>

                </Grid>
                </GroupBox>
            
                <!-- Available Forums header Stack Panel -->
            <StackPanel  x:Uid="StackPanel_21" Margin="5,0,5,0" Grid.Row="2">
                <StackPanel x:Uid="StackPanel_22" Orientation="Horizontal" Margin="0,5,0,5">
                    <Label Name="AvilableForums" Padding="5,0,0,0" 
                           VerticalAlignment="Center">Available Forums ( Forums in the selected brand and locale to which you are not subscribed)</Label>
                </StackPanel>
            </StackPanel>

            
            <!-- Available forums list  -->
            <ListView Grid.Row="3" x:Uid="AvailableForumsListView" 
                      ItemsSource="{Binding Path=AvailableForumsCollectionView}" 
				      HorizontalAlignment="Stretch" 
                      VerticalAlignment="Stretch"  
                      SelectionMode="Multiple"
                      Name="AvailableForumsListView"
                      SelectedIndex="-1" 
                      ScrollViewer.VerticalScrollBarVisibility="Auto" 
                      IsSynchronizedWithCurrentItem="True" 
                      Margin="-1,0,-1,0"  >
                <ListView.View>
                    <GridView>
                        <GridViewColumn   CellTemplate="{StaticResource NewIconTemplate}" />
                        <GridViewColumn Header="Forum Name" Width="200"  DisplayMemberBinding="{Binding Path=DisplayName}"/>
                        <GridViewColumn   CellTemplate="{StaticResource ModeratorIconTemplate}" />
                        <GridViewColumn   CellTemplate="{StaticResource PublicForumIconIconTemplate}" />
                        <GridViewColumn Header="Description" CellTemplate="{StaticResource DescriptionExpanderTemplate}"/>
                    </GridView>
                </ListView.View>
            </ListView>
            
            <!-- Add button StackPanel -->
            <StackPanel x:Uid="StackPanel_24" Grid.Row="4">
                <StackPanel x:Uid="StackPanel_13">
                    <Button  HorizontalAlignment="Right" x:Name="AddButton"  x:Uid="AddButton" Width="50" 
                             Command="{x:Static ForumsClient:Commands.AddToPreviewArea}"
                             ToolTip="Adds Forum to Preview Area" >Add</Button>
                </StackPanel>
            </StackPanel>

            <!-- Subscription Preview Area -->
            <StackPanel x:Uid="StackPanel_25" Margin="0,5,0,15" Grid.Row="5">
                <Label Name="SubscriptionPreviewAreaLabel" x:Uid="SubscriptionPreviewAreaLabel" Padding="5,0,0,0"  ToolTip="Forums you selected for subscription." VerticalAlignment="Center">Subscription Preview Area (Forums below may be subscribed by clicking the Finish button)</Label>
                <ListView x:Uid="PreviewForumsListView" Height="150" 
                          ItemsSource="{Binding Path=PreviewForumsCollectionView}" 
                          Name="PreviewForumsListView" SelectedIndex="-1" 
                          SelectionMode="Multiple"
                          ScrollViewer.VerticalScrollBarVisibility="Auto" 
                          IsSynchronizedWithCurrentItem="True" 
                          Margin="-1,0,-1,0" >
                    <ListView.View>
                        <GridView>
                            <GridViewColumn   CellTemplate="{StaticResource NewIconTemplate}" />
                            <GridViewColumn Header="Forum Name" Width="200"  DisplayMemberBinding="{Binding Path=DisplayName}"/>
                            <GridViewColumn   CellTemplate="{StaticResource ModeratorIconTemplate}" />
                            <GridViewColumn   CellTemplate="{StaticResource PublicForumIconIconTemplate}" />
                            <GridViewColumn Header="Description" CellTemplate="{StaticResource DescriptionExpanderTemplate}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
                <StackPanel x:Uid="StackPanel_26">
                    <Button HorizontalAlignment="Right" x:Uid="RemoveButton" Name="RemoveButton"
                            Command="{x:Static ForumsClient:Commands.RemoveFromPreviewArea}"
                            Width="60" ToolTip="Removes the selected Forum from Preview Area" >Remove</Button>
                </StackPanel>
            </StackPanel>

            <!-- Finish & Cancel Buttons -->
            <StackPanel x:Uid="StackPanel_27" Grid.Row="6">
                <StackPanel x:Uid="StackPanel_28" Orientation="Horizontal"  HorizontalAlignment="Right" >
                    <Button x:Uid="FinishButton" Name="FinishButton" Content="Finish" Width="75" Height="32"
                            ToolTip="Click this button to subscribe to forums listed in the Subscription Preview Area" 
                            Command="{x:Static ForumsClient:Commands.SubscribeToForums}"
                             />
                    <Button x:Uid="CancelButton" Name="CancelButton" Command="Close" IsCancel="True"  Width="75" Height="32" >Cancel</Button>
                </StackPanel>
            </StackPanel>

        </Grid>    
    </Grid>
</UserControl>
